package com.fr.cell.undo;

import com.fr.base.FRContext;
import com.fr.base.file.CacheManager;
import com.fr.cell.GridSelection;
import com.fr.cell.ReportPane;
import com.fr.util.Utils;
import java.io.File;
import javax.swing.JScrollBar;

public abstract class UndoState
{
  protected ReportPane reportPane;
  protected GridSelection gridSelection;
  protected int verticalValue = 0;
  protected int horizontalValue = 0;
  protected boolean isCacheable = true;
  protected File cacheDirectory;
  protected File cacheFile;

  protected UndoState()
  {
  }

  protected UndoState(ReportPane paramReportPane, GridSelection paramGridSelection, int paramInt1, int paramInt2, boolean paramBoolean)
  {
    this.reportPane = paramReportPane;
    this.isCacheable = paramBoolean;
    this.gridSelection = paramGridSelection;
    this.verticalValue = paramInt1;
    this.horizontalValue = paramInt2;
    evaluateReportTemplate();
  }

  protected abstract void evaluateReportTemplate();

  protected File getCacheDirectory()
  {
    if (this.cacheDirectory == null)
    {
      this.cacheDirectory = FRContext.getCacheManager().getCacheDirectory();
      Utils.mkdirs(this.cacheDirectory);
      this.cacheDirectory.deleteOnExit();
    }
    return this.cacheDirectory;
  }

  public void applyState()
  {
    this.reportPane.setGridSelection(this.gridSelection);
    this.reportPane.getVerticalScrollBar().setValue(this.verticalValue);
    this.reportPane.getHorizontalScrollBar().setValue(this.horizontalValue);
    this.reportPane.setUndoState(this);
    this.reportPane.repaint();
  }
}